<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<script src="${ctx}/assets/js/jquery.validate.js"></script>
<script type="text/javascript">
var butFlag=$("#operateType").val();

var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	$(function(){
	 	if($("#prompt").val()!='1'){
			$(".unShow").css("display","none");
		}
	 	cleanPwd();
	});	
	//alert(butFlag);
});

$("#passForm").validate({
    errorElement: 'div',
    errorClass: 'help-block',
    focusInvalid: false,
    onfocusout: function(element) {
        this.element(element);
	},
    rules: {
       oldPwd: {
          required: true,
          maxlength:32
       },
       newPwd: {
          required: true,
          maxlength:32
       },
       confirmPwd: {
    	 required: true,
    	 maxlength:32,
         equalTo: "#newPwd"
       }
    },

    messages: {
    	oldPwd: {
           required:"原密码不能为空，请重新输入原密码!"
        }, 
       newPwd: {
           required:"新密码不能为空，请重新输入新密码!"
        }, 
       confirmPwd: {
           required:"确认密码不能为空，请重新输入确认密码!",
        	equalTo:"和新密码不一致"
        }        
    },

    highlight: function (e) {
        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
    },

    success: function (e) {
        $(e).closest('.form-group').removeClass('has-error').addClass('has-info');
        $(e).remove();
    },

    errorPlacement: function (error, element) {
        error.insertAfter(element.parent());
    }
});	

$('#oldPwd').on('blur', function() {
    $("#passForm").validate().element( this );
});

function checkNewPwd(newPwd){
	$(".help-block").css({"margin-bottom":"0px"}); 
	var num = false;
	var uppercase = false;
	var lowercase = false;
	var symbol = false;
	for (var i=0;i<newPwd.length;i++){
		var character = newPwd.charAt(i);
		if (character<= 9 && character >= 0){
			num = true;
		}else if (character <= 'Z' && character >= 'A'){
			uppercase = true;
		}else if (character <= 'z' && character >= 'a'){
			lowercase = true;
		}else{
			symbol = true;
		}
	}

	var number = 0;
	if(num){
		number++;
	}
	if(uppercase){
		number++;
	}
	if(lowercase){
		number++;
	}
	if(symbol){
		number++;
	}
	if(number >= 2){
		return true;
	}else{
		return false;
	}
}


//确认修改按钮
function updatePwd(){
	var newPwd = $("#newPwd").val();
	if(newPwd.length < 6){
		$('#newPwdLength').show();
		return;
	}
	
	if(!checkNewPwd(newPwd)){
		$('#newPwdInfo').show();
		return;
	}
	
	if ($("#passForm").valid() == false) {
		return;
	} 
	
	
	$.ajax({
	url : "${ctx}/user/updatePwd",
	async : false,
	data : $("#passForm").serialize(),
	type : "POST",
	dataType : "json",
	success: function(data){	
		    if(data[0]=="ok"){
		    	alert(data[1]);
		    	cleanPwd();	
			    $('#userDetailIframe').dialog("close");
		    }else{
		    	alert(data[1]);
		    	cleanPwd();
		    }
		    
	    },
	 error: function(data){
		   alert(data.responseText);
		   cleanPwd();	
	 }
	});	
}
function cleanPwd(){
	$("#oldPwd").val("");
	$("#newPwd").val("");
	$("#confirmPwd").val("");
}
</script>
 <div class="row">
	<div class="table-header">
		密码修改
	</div>
	<div class="alert alert-info col-sm-12">
		<button type="button" class="close" data-dismiss="alert">
			<i class="ace-icon fa fa-times"></i>
		</button>
		<strong>注: </strong>
			提示：为了您的账号安全，建议您定期修改个人密码。<br />
			           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;修改密码必须包含大写字母[A-Z]，小写字母[a-z]，数字，以及特殊字符至少其中两种。
			<br />
	</div>
 </div>
 <div class="row">
   <div class="col-xs-12">
   
		<form id="passForm" name="passForm" class="form-horizontal" role="form">
			<input type="hidden" id="prompt" name="prompt" value="${prompt}">	
			<input type="hidden" id="operateType" name="operateType" value="${operateType}">	
			<input type="hidden" id="user_Id" name="userId" value="${userId}">		
			<div class="form-group">
					<label class="col-sm-4 control-label no-padding-right" for="_oldPwd">原密码：</label>
					<div class="col-sm-8">
					   <div class="clearfix">
						<input type="password" class="col-xs-6 col-sm-6"  name="oldPwd" id="oldPwd" maxlength="32" />
						</div>
					</div>
		   </div>
		   
		   <div class="form-group">
					<label class="col-sm-4 control-label no-padding-right" for="_newPwd">新密码：</label>
					<div class="col-sm-8">
					  <div class="clearfix">
						<input type="password" class="col-xs-6 col-sm-6"  name="newPwd" id="newPwd" maxlength="32" />
					  </div> 
					  <div id="newPwdInfo"  style="display:none;color:#d16e6c;margin-top:0px" class="">必须包含大写字母，小写字母，数字，以及特殊字符至少其中两种</div>
					  <div id="newPwdLength"  style="display:none;color:#d16e6c;margin-top:0px" class="">密码不能少于6位</div>
					</div>
		   </div>
		   
		    <div class="form-group">
					<label class="col-sm-4 control-label no-padding-right" for="_confirmPwd">确认密码：</label>
					<div class="col-sm-8">
					   <div class="clearfix">
						<input type="password" class="col-xs-6 col-sm-6"  name="confirmPwd" id="confirmPwd" maxlength="32" />
					   </div>
					</div>
		   </div>
		   </form>
		    
		    <!--<div class="clearfix">
			<div class="pull-right tableTools-container col-xs-4 col-sm-4">
				<div class="btn-group btn-overlap">
					<div class="btn-group" title="修改">
						<button  type="button" id="update" class="btn btn-purple ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button">
							<span class="ui-button-text"><i></i>&nbsp; 修改</span>
						</button>	
					</div>
				</div>
			</div>
		</div>-->
	</div>
</div>